//
//  ThemeCGFloatPicker.swift
//  HeadlineNews
//
//  Created by han on 2019/7/24.
//  Copyright © 2019 han. All rights reserved.
//

import UIKit

final class ThemeCGFloatPicker: ThemePicker {
    convenience init(keyPath: String) {
        self.init(v: { CGFloat(ThemeManager.number(for: keyPath)?.doubleValue ?? 0) })
    }
    
    convenience init(keyPath: String, map: @escaping (Any?) -> CGFloat? ) {
        self.init(v: { map(ThemeManager.value(for: keyPath))})
    }
    
    convenience init(floats: CGFloat...) {
        self.init(v: { ThemeManager.element(for: floats) })
    }
    
    
    
}

extension ThemeCGFloatPicker: ExpressibleByArrayLiteral {
    convenience init(arrayLiteral elements: CGFloat...) {
        self.init(v: { ThemeManager.element(for: elements) })
    }
}

extension ThemeCGFloatPicker: ExpressibleByStringLiteral {
    convenience init(stringLiteral value: String ) {
        self.init(keyPath: value)
    }
    
    convenience init(extendedGraphemeClusterLiteral value: String) {
        self.init(keyPath: value)
    }
}

extension ThemeCGFloatPicker: ExpressibleByUnicodeScalarLiteral {
    convenience init(unicodeScalarLiteral value: String) {
        self.init(keyPath: value)
    }
}

extension ThemeCGFloatPicker {
    class func pickerWithKeyPath(_ keyPath: String) -> ThemeCGFloatPicker {
        return ThemeCGFloatPicker(keyPath: keyPath)
    }
    
    class func pickerWithKeyPath(_ keyPath: String, map:@escaping (Any?) -> CGColor?) -> ThemeCGFloatPicker {
        return ThemeCGFloatPicker(v: { map(ThemeManager.value(for: keyPath))})
    }
    
    class func pickerWithColors(_ floats: [CGFloat]) -> ThemeCGFloatPicker{
        return ThemeCGFloatPicker(v: { ThemeManager.element(for: floats) })
    }
}



